// Achievement made by Dark Shadow [DK]
// Modified by RabidToaster

local time = achievements.GetValue( "I Like Walking", "total", 0 )

local function IsOnGround( ply )
	local trace = util.QuickTrace( ply:GetPos(), Vector( 0, 0, -50 ), ply )
	
	// We're very definitely on the world.
	if ( trace.HitWorld ) then return true end
	
	// Check for func_brushes, weird doors etc.
	if ( ValidEntity( trace.Entity ) ) then
		if ( string.Left( trace.Entity:GetClass() or "", 5 ) == "func_" ) then return true end
	end
	
	// We're not on the ground.
	return false
end

local target = 36000
local function Update()
	local ply = LocalPlayer()
	if ( !ValidEntity( ply ) ) then return end
	
	if ( time != target && IsOnGround( ply ) && ply:GetMoveType() == MOVETYPE_WALK && !ply:InVehicle() ) then
		time = math.Clamp( time + 1, 0, target )
		achievements.SetValue( "I Like Walking", "total", time )
		
		if ( time >= target ) then
			timer.Destroy( "Achievements.ILikeWalking" )
		end
	end
	
	achievements.Update( "I Like Walking", time / target, achievements.FormatTime( time, "h:m:s" ) )
end
timer.Create( "Achievements.ILikeWalking", 1, 0, Update )

achievements.Register( "I Like Walking", "Spend a total of 10 hours on the ground.", "achievements/dolike", time / target, string.FormattedTime( time, "%02i:%02i" ) )